<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>设备管理</title>
		<link href="css/new_file.css" rel="stylesheet" type="text/css">
		<link href="css/mui.min.css" rel="stylesheet" type="text/css">

		<script charset="UTF-8" src="js/config.js"></script>
		<script charset="UTF-8" src="js/testActivityName.js"></script>
		<script charset="UTF-8" src="js/core.js"></script>
		<script charset="UTF-8" src="js/cipher-core.js"></script>
		<script charset="UTF-8" src="js/tripledes.js"></script>
		<script charset="UTF-8" src="js/mode-ecb.js"></script>
		<script src="js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="js/zepto.min.js"></script>
		<script type="text/javascript" src="js/spin.min.js"></script>
		<script charset="UTF-8" src="js/mui.min.js"></script>
		<script src="js/echarts.min.js"></script>
	</head>
	<style>
		.mui-bar{
			     padding-right: 0px; 
			     padding-left:0px; 
		}
		*{
		    margin:0;
		    padding:0;
		}
	</style>
	<body>
		<div class="spin"></div>
		<header id="header" class="mui-bar mui-bar-transparent" style="width: 100%;">
				<div class="head-zhjf">
					<img src="images/fanhui@3x.png" class="ryjk-tx" onclick="Returnfunction()">
					<div id="imagestianjia">
					</div>
					<p>设备更换</p>
				</div>
				<div class="search-div">
					<div class="g-bd2">
						<div class="search-l-div">
							<div class="seach-l-a">
								<img class="sousuo-acx" src="images/sousuo-btn@3x.png">
								<input id="cowReplacementData" class="xtsz-search-btn" type="text" value="请输入搜索内容" onfocus="if(value==defaultValue){value='';this.style.color='#393e46'}" onblur="if(!value){value=defaultValue;this.style.color='#cdcdcd'}">
							</div>
						</div>
						<div class="seach-r-div" onclick="equipmentReplacementSearch()">
							<img class="cx-div" src="images/sousuo-a-btn@3x.png" />
						</div>
					</div>
				</div>
				
						
		</header>
		
		<div style="margin-top: 90px;" class="clear"></div>

		<div id="noApplicationRecord">
			<div style="width: 100%;height: 100%;text-align: center;margin-top: 45%;">
				<img src="images/nodata.png" style="width: 200px;height: 140px;"/>
			</div>
		</div>
		<div id="hddb" style="position: fixed;right: -3px;bottom: 30px;border-radius: 25px;width: 50px;height: 50px;text-align: center;">
			<img src="img/hddb.png" style="width: 32px;height: 32px;    margin-top: 9px;" onclick="goTop()">
		</div>
		
		
		<script>
			var numberStr = 2;
			var butStr = 0;
			var noApplicationRecord = document.getElementById('noApplicationRecord');
			var cowReplacementData = JSON.parse(localStorage.getItem('cowReplacementData'));
			var imagestianjia = document.getElementById('imagestianjia');
			var equipmentSeachData = JSON.parse(localStorage.getItem('equipmentSeachData'));
			var CowNumber = JSON.parse(localStorage.getItem('CowNumber'));
			var CowshedNumber = JSON.parse(localStorage.getItem('CowshedNumber'));
			var CattleNumber = JSON.parse(localStorage.getItem('CattleNumber'));
			var Cattlemodify = JSON.parse(localStorage.getItem('Cattlemodify'));
			if(CowNumber == 10 || CattleNumber == 100 || Cattlemodify == 100 || CowshedNumber == 10) {} else {
				function setDiv1(item) {
					var div = '<div class="head-zhjf-img" onclick="addequipmentReplacement()"><img src="images/tianjia-btn@3x.png"></div>'
					return div
				}
				function getnoApplicationData1() {
					var html = ''
					html += setDiv1()
					imagestianjia.innerHTML = html
				}
				window.onload = getnoApplicationData1();
			}
			console.log(cowReplacementData);
			if(cowReplacementData.length != 20) {
				butStr = 1;
			}
			//绘制单个div
			if(cowReplacementData.length != 0) {
				huitu();
			}
			
			//获取滚动条当前的位置 
			function getScrollTop() {
				var scrollTop = 0;
				if(document.documentElement && document.documentElement.scrollTop) {
					scrollTop = document.documentElement.scrollTop;
				} else if(document.body) {
					scrollTop = document.body.scrollTop;
				}
				return scrollTop;
			}
			//获取当前可视范围的高度 
			function getClientHeight() {
				var clientHeight = 0;
				if(document.body.clientHeight && document.documentElement.clientHeight) {
					clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
				} else {
					clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
				}
				return clientHeight;
			}

			//获取文档完整的高度 
			function getScrollHeight() {
				return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
			}
			window.onscroll = function() {
//				console.log("x="+getScrollTop()+"  y="+getClientHeight()+" z="+getScrollHeight());
				if(getScrollTop() + getClientHeight()>= getScrollHeight()-6){ //ajax从这里开始
					if(butStr == 1) {
						mui.toast("没有更多数据了")
					} else {	
						var keys = JSON.parse(localStorage.getItem('key'));
						var map = {};
						if (equipmentSeachData != '请输入搜索内容') {
							map.searchKey = equipmentSeachData;
						}
						map.key = keys;
						map.page = numberStr;
						map.size = "20";
						map.phoneType = "android";
						map.language = "zh";
						var jsonStr = JSON.stringify(map);
						console.log(jsonStr);

						var ajaxTimeoutTest = $.ajax({
							type: "POST",
							url: url_prefix + "changeList",
							dataType: 'JSON',
							timeout: 10000,
							data: {
								'request': encryptByDES(jsonStr)
							},
							success: function(data) {
								var str1 = decryptByDESModeEBC(data["result"]); //解密
								var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
								var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
								var datas = JSON.stringify(str2); //转JSON字符串
								var aa = datas.replace(/\\n/g, " "); //去掉换行
								var objs = eval('(' + aa + ')');
								var bb = eval('(' + objs + ')');
								if(bb.head.status == 1) {
									if(bb.data.length != 20) {
										butStr = 1;
									}
									if(bb.data.length == 0) {
										mui.toast("没有更多数据了");
									}
									for(var i = 0; i < bb.data.length; i++) {
										cowReplacementData.push(bb.data[i]);
									}
									console.log(cowReplacementData);
									numberStr++;
									if(cowReplacementData.length != 0) {
										huitu();
									}
								} else {
									mui.alert(bb.head.info);
								}
							},
							complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数　　
								dismissDialog();　　
								if(status == 'timeout') { //超时,status还有success,error等值的情况　　　　　
									ajaxTimeoutTest.abort();　　　　　
									mui.alert("网络请求超时...");　　　　
								}　　
							}
						});
					}
				}
			}
			function huitu() {
				function setDiv(item, i) {//onclick="Obtainequipment(this.id)"
					var div = '<div class="liebiao-div" id="' + i + '" ><img class="liebiao-que-l" src="images/banyuan@3x.png" /><img class="liebiao-que-r" src="images/banyuan-right@3x.png" /><div class="liebiao-aa"><p class="liebiao-l">设备编号A</p><p class="liebiao-r">' +
						item.col2a   +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">设备编号B</p><p class="liebiao-r">' +
						item.col2b   +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">耳号A</p><p class="liebiao-r">' +
						item.overbita +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">更换时间</p><p class="liebiao-r">' +
						item.replace_date    +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">备注</p><p class="liebiao-r">' +
						item.remake +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">创建人</p><p class="liebiao-r">' +
						item.create_name +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">创建时间</p><p class="liebiao-r">' +
						item.create_time +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">耳号B</p><p class="liebiao-r">' +
						item.overbitb   +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">设备序列号A</p><p class="liebiao-r">' +
						item.deviceaIdLast   +
						'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">设备序列号B</p><p class="liebiao-r">' +
						item.devicebIdLast   +
						'</p><div class="clear"></div></div></div><div class="clear"></div></div>'
					return div
				}
				function getnoApplicationData() {
					var html = ''

					for(var i = 0; i < cowReplacementData.length; i++) {
						html += setDiv(cowReplacementData[i], i)
					}
					noApplicationRecord.innerHTML = html
				}
				window.onload = getnoApplicationData();
			}
			function goTop(){
			    //速度
			    var speed = 100;
			    //开启定时器
			    
			    var timer = setInterval(function(){
			        //获取滚动条的高度
			        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
			        //设置滚动的高度
			        document.documentElement.scrollTop = document.body.scrollTop = (scrollTop - speed);
			        //清除定时器
			        speed += 30;
			        if(scrollTop <= 0){
			            clearInterval(timer);
			        }
			    },30)
			}
			function showLogin(){
			    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
			    if (scrollTop > 0) {
			    	$("#hddb").css("right","-3px");
			    } else{
			    	$("#hddb").css("right","-63px");
			    } 
			    //每秒执行一次,showTime()  
			    setTimeout("showLogin()",500);  
			}
			showLogin()
		</script>
	</body>
</html>